
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
</head>
<link rel="stylesheet" href="${path}/layui/css/layui.css" media="all">
<script src="${path}/js/jquery.min.js"></script>
<script src="${path}/layui/layui.js"></script>
<body>
<div id="plan" style="display: none">
    <table class="layui-table" lay-filter="planTable" id="planTable"></table>
</div>
    <form class="layui-form" action="" style="margin-top: 30px;">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">会员名</label>
                <div class="layui-input-inline" style="width: 200px;">
                    <input id="username" type="text"  name="name" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-input-inline" style="width: 100px;">
                    <button type="button" class="layui-btn layui-btn-normal" onclick="SearchData();"><i class="layui-icon layui-icon-search"></i> 查询</button>
                </div>
            </div>

        </div>
    </form>
    <table class="layui-table" lay-data="{id:'buyTable',url:'${path}/gifttable/buyjilu', page:true,toolbar:'#toolbarDemo',defaultToolbar: ['filter', 'print', 'exports'],even: true}"
           lay-filter="buyTable">
        <thead>
        <tr>
            <th lay-data="{type:'checkbox'}">hello</th>
            <th lay-data="{field:'cardid'}">会员卡号</th>
            <th lay-data="{field:'namer'}">会员名称</th>
            <th lay-data="{templet:'#viptype'}">会员卡</th>
            <th lay-data="{field:'giftname'}">礼品名称</th>
            <th lay-data="{field:'integral'}">消费积分</th>
            <th lay-data="{field:'num'}">数量</th>
            <th lay-data="{field:'phone'}">手机号</th>
            <th lay-data="{field:'timer'}">时间</th>
        </tr>
        </thead>
    </table>
</body>
<script>
    function SearchData() {
        layui.table.reload("buyTable",{
            page:{
                curr:1
            },
            where:{
                "namer":$("#username").val(),
            }
        })
    }
    layui.use(["table","form"],function() {
        var table = layui.table;
        table.on('toolbar(buyTable)',function (obj) {
            switch (obj.event) {
                case "batchDelete":
                    var rows = table.checkStatus('buyTable');
                    var data = rows.data;
                    if(data.length == 0){
                        layer.msg("请选择要删除的数据",function(){});
                        return;
                    }
                    layer.confirm('确定要删除这么多数据吗？',{icon:5,title:'友情提示'},function (index) {
                        var params = "";
                        // var num="";
                        for(let buyTable of data){
                            params += "ids="+buyTable.id+"&";
                            // num += "ids="+buyTable.cardid+"&";
                        }
                        $.post('${path}/gifttable/batchDelete',params,function () {
                            <%--$.post('${path}/gifttable/xiangxibatchDelete',num,function () {--%>
                                layer.msg("删除成功");
                                layer.close(index);
                                table.reload('buyTable');
                            // })

                        });
                    });
                    break;
            }
        })
    })
</script>
<%--绑定vip会员卡--%>
<script type="text/html" id="viptype">
{{d.vipType.name}}
</script>
<script type="text/html" id="giftid">
{{d.gift.name}}
</script>
<%--导航按钮--%>
<script type="text/html" id="toolbarDemo">
    <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="batchDelete"><i class="layui-icon layui-icon-delete"></i> 批量删除</button>
</script>
</html>
